include $(top_srcdir)/common.mk

ACLOCAL_AMFLAGS = -I m4

if COVERAGE
AM_CFLAGS += --coverage
endif

EXTRA_DIST = ${top_srcdir}/README.md \
	     ${top_srcdir}/LICENSE \
	     ${top_srcdir}/common.mk \
	     ${top_srcdir}/tests/dummy_data/cve.ini \
	     ${top_srcdir}/tests/dummy_data/nvdcve-2.0-2002.xml \
	     ${top_srcdir}/tests/dummy_data/rpm/package.spec \
	     ${top_srcdir}/tests/dummy_data/rpm/package2.spec \
	     ${top_srcdir}/tests/dummy_data/rpm/packages \
	     ${top_srcdir}/tests/dummy_data/rpm/package-1.-5.src.rpm \
	     ${top_srcdir}/tests/dummy_data/rpm/CVE-2014-5461.patch \
	     ${top_srcdir}/tests/dummy_data/rpm/cve-2013-4459.nopatch \
	     ${top_srcdir}/tests/dummy_data/eopkg/pspec.xml \
	     ${top_srcdir}/tests/dummy_data/eopkg/files/security/cve-2014-5461.patch \
	     ${top_srcdir}/tests/dummy_data/eopkg/files/security/cve-2013-4459.nopatch \
	     ${top_srcdir}/tests/dummy_data/pkgbuild/PKGBUILD \
	     ${top_srcdir}/tests/dummy_data/pkgbuild/cve-2014-5461.patch \
	     ${top_srcdir}/test-init.sh \
	     ${top_srcdir}/data/packages.template

NULL =
CLEANFILES =

dist_man_MANS = \
	docs/cve-check-tool.1

# Install the template file to disk
templatedir=$(datadir)/cve-check-tool/
template_DATA = data/packages.template

include src/Makefile.am

if COVERAGE
coverage:
	mkdir -p coverage
	lcov --compat-libtool --directory . --capture --output-file coverage/report
	genhtml -o coverage/ coverage/report
AM_CFLAGS += --coverage
endif

if ENABLE_UNIT_TESTS
# Test suites
AM_TESTS_ENVIRONMENT = \
	eval $(srcdir)/test-init.sh "${top_srcdir}" "$(top_builddir)";

distclean-local:
	rm -rf ${top_builddir}/tests/dummy_install

# Tests
TESTS = \
	check_core \
	check_database \
	check_hashmap \
	check_packaging \
	check_template

check_PROGRAMS = \
	check_core \
	check_database \
	check_hashmap \
	check_packaging \
	check_template

check_core_SOURCES = \
	tests/check-core.c

check_core_CFLAGS = \
	$(CVE_CHECK_TOOL_CFLAGS) \
	$(AM_CFLAGS) \
	$(CHECK_CFLAGS)

check_core_LDADD = \
	$(CVE_CHECK_TOOL_LIBS) \
	$(CHECK_LIBS)

check_database_SOURCES = \
	tests/check-database.c

check_database_CFLAGS = \
	$(CVE_CHECK_TOOL_CFLAGS) \
	$(AM_CFLAGS) \
	$(CHECK_CFLAGS)

check_database_LDADD = \
	$(CVE_CHECK_TOOL_LIBS) \
	$(CHECK_LIBS)

check_hashmap_SOURCES = \
	tests/check-hashmap.c

check_hashmap_CFLAGS = \
	$(CVE_CHECK_TOOL_CFLAGS) \
	$(AM_CFLAGS) \
	$(CHECK_CFLAGS)

check_hashmap_LDADD = \
	$(CHECK_LIBS)

check_packaging_SOURCES = \
	tests/check-packaging.c

check_packaging_CFLAGS = \
	$(CVE_CHECK_TOOL_CFLAGS) \
	$(AM_CFLAGS) \
	$(CHECK_CFLAGS) \
	-DTEST_SUITE_BUILD

check_packaging_LDADD = \
	$(CVE_CHECK_TOOL_LIBS) \
	$(CHECK_LIBS) \
	-ldl

check_template_SOURCES = \
	tests/check-template.c

check_template_CFLAGS = \
	$(CVE_CHECK_TOOL_CFLAGS) \
	$(AM_CFLAGS) \
	$(CHECK_CFLAGS)

check_template_LDADD = \
	$(CVE_CHECK_TOOL_LIBS) \
	$(CHECK_LIBS)

@VALGRIND_CHECK_RULES@
endif
